<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="./lib/vue.js"></script>
    <title>父组件传值</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model="msg">
        <h1>{{msg}}</h1>
        <my-com @subfun="cb"></my-com>

    </div>
    <template id="mytemp">
        <div>
            <p>{{msg}}</p>
            <input type="button" value="触发向父组件传递数据" @click="send">
        </div>
    </template>
</body>
<script>

    Vue.component("myCom", {
        template: "#mytemp",
        data() {
            return {
                msg: "这是组件内部的变量"
            }
        },
        props: [],
        methods: {
            send() {
                this.$emit('subfun', this.msg)
            }
        }
    })
    var vm = new Vue({
        el: '#app',
        data: {
            msg: '123'
        },
        methods: {
            cb(arg) {
                console.log(arg);
                this.msg = arg
            }
        }
    })
</script>
</html>